package com.itheima.cases.date_time_format;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class Test {
    public static void main(String[] args) {
        // 测试；datatimeformat格式化

        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy年MM-dd HH:mm:ss");

        // 时间格式转字符串
        String now = dateTimeFormatter.format(LocalDateTime.now());
        System.out.println(now);

        // 字符串转时间格式
        LocalDateTime pastTime = LocalDateTime.parse("2003年04-01 10:01:36", dateTimeFormatter);
        System.out.println(pastTime);

        // LocalDateTime 转字符串
        LocalDateTime now2 = LocalDateTime.now();
        String format3 = now2.format(dateTimeFormatter);
        System.out.println(format3);

    }
}
